package com.service.websocket.handler.business;

import com.service.websocket.handler.AbstractMessageHandler;
import com.service.websocket.to.Topic;
import com.service.websocket.to.MessageTO;
import org.springframework.stereotype.Component;

/**
 * @author xinggj
 * @description: 样例
 * @date 2020/4/15 16:17
 */
@Component
public class DemoHandler extends AbstractMessageHandler {


    /**
     * 发送消息案例：
     * {"data":"test","topic":"demo"}
     *
     * 返回消息案例：
     * {"data":{"data":"hello test","time":2,"topic":"demo"},"message":"success","status":200}
     * @param tuple
     * @return
     * @throws Exception
     */

    @Override
    public String produce(MessageTO tuple) throws Exception {
        tuple.setData("hello "+tuple.getData());
//        sendMessageToBus(tuple);
        return MessageTO.SUCCESS;
    }

    @Override
    public String getTopic() {
        return Topic.DEMO.getValue();
    }

    @Override
    public Object getParams(Object map) throws Exception {
        if (map == null){
            return new RuntimeException("参数为空");
        }
        return String.valueOf(map) ;
    }

    @Override
    public void afterConnectionClosed(String winId) {
        System.out.println("根据winId查询出业务进行清除处理");
    }
}
